package com.eling.elcms.basedoc.model;

import com.eling.elcms.community.model.Organization;
import com.eling.elcms.core.dao.annotation.Between;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.OrderCriteriaEnhancer;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.privilege.model.User;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;

/**
 * 地址档案
 * @author liuying
 * 
 * @edit zhoulin 
 * @date 2016年7月12日16:37:43
 */
@Entity
@Indexed
@Table(name = "bd_communitydata")
@CriteriaEnhancers(criteriaEnhancers = {
		@CriteriaEnhancer(impl = OrderCriteriaEnhancer.class, parameter = "code")})
public class CommunityData extends BaseModel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1188010804029985196L;
	@Id
	@DocumentId
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@In
	private Long pkCommunityData;
	
	/** 名称（需求变更，对应页面-乡（镇）/社区）*/
	@Field
	@Column
	private String name;
	
	/** 编码*/
	@Field
	@Column
	private String code;
	
	/** 状态*/
	@Enumerated(EnumType.STRING)
	@Field
	@In
	@FieldBridge(impl = EnumBridge.class)
	private Status status;
	
	/** 启用时间 */
	@Column
	@Field
	@Between
	private Date enableTime;
	
	/** 停用时间 */
	@Column
	@Field
	@Between
	private Date disableTime;
	
	/** 创建时间 */
	@Column
	@Field
	@Between
	private Date createTime;
	
	/** 创建人 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkOperator")
	@IndexedEmbedded
	private User operator;
	
	/** 所属机构 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkOrganization")
	@IndexedEmbedded
	private Organization organization;
	
	/** 省/市/区（县）*/
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkAddress")
	@IndexedEmbedded
	private AdministrativeDivision address;
	
	/** 乡（镇）/街道/村 （需求变更，不需维护）*/
	@Column
	@Field
	private String street;
	
	/**
	 * 状态
	 * @author
	 */
	@JsonSerialize(using = EnumSerializer.class)
	public static enum Status {
		Setting("启用"), BlockUp("停用");

		private String display;

		Status(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}
	@Version
	private Integer version;
	
	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public Date getEnableTime() {
		return enableTime;
	}

	public void setEnableTime(Date enableTime) {
		this.enableTime = enableTime;
	}

	public Date getDisableTime() {
		return disableTime;
	}

	public void setDisableTime(Date disableTime) {
		this.disableTime = disableTime;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public User getOperator() {
		return operator;
	}

	public void setOperator(User operator) {
		this.operator = operator;
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public AdministrativeDivision getAddress() {
		return address;
	}

	public void setAddress(AdministrativeDivision address) {
		this.address = address;
	}

	public Long getPkCommunityData() {
		return pkCommunityData;
	}

	public void setPkCommunityData(Long pkCommunityData) {
		this.pkCommunityData = pkCommunityData;
	}

	public Organization getOrganization() {
		return organization;
	}

	public void setOrganization(Organization organization) {
		this.organization = organization;
	}
	
}
